#include "GunPhysics.h"
/* Set bullet container data */
	 void GunPhysics::_initBulletContainer() {
		_armyData->bulletContainer = new BulletContainer(_armyData->targetRect, BulletArmy);
		_armyData->bulletContainer->updateData(_GUN_DATA_DISTANCE_BULLET, _GUN_DATA_DELAY_TWO_BULLET, 1, _ID_BULLET_LEVEL_0);
	}

	/* Fire with target direction */
	 void GunPhysics::_updateBulletContainer() {
		if (!_armyData->_checkInRange() || _armyData->isDead) return;
		if (_armyData->bulletContainer->checkCanFire()) {
			_armyData->bulletContainer->fire(_armyData->getRect()->X, _armyData->getRect()->Y, 0, _armyData->targetRect, _armyData->isHalf);
		}
		_armyData->bulletContainer->update(0);
	}

	 void GunPhysics:: _setToDead(int actiondata) {
		_life -= actiondata;
		if (_life <= 0 ) {
			_armyData->canInteract = false;
			_armyData->isDead = true;
			EffectManager::getInstatnse()->createEffect(EffectType::TYPE_Object_Fire, _armyData->getRect()->X, _armyData->getRect()->Y);
		}
	}

	/* Constructor to set ref, with not null ref */
	GunPhysics::GunPhysics(ArmyData* data) {
		_armyData = data;
		_life = 5;
		_initBulletContainer();
	}

	/* Implement from abstract update method.
	Check with target to set direction of bullet fired 	
	*/
	 void GunPhysics::update(long timetick) {
		_updateBulletContainer();
	}

	 void GunPhysics::setIsHurt(ACTIONS action, int action_data) {
		if (action == ACTIONS_IS_HURT && !_armyData->isDead) {
			_setToDead(action_data);
		}
	}